package com.twu.biblioteca.services;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class LibraryIOService implements ILibraryIOService {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    @Override
    public void output(String text) {
        System.out.println(text);
    }

    @Override
    public MenuOption getMenuInput() {
        String input = getTextInput();

        try {
            int value = Integer.parseInt(input);

            return MenuOption.fromInt(value);

        } catch (NumberFormatException exception) {
            return MenuOption.INVALID;
        }
    }

    @Override
    public String getTextInput() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            return "";
        }
    }
}
